#include "BattleFirePrefix.h"

bool CanReadFD(BattleFireSocket fd, int second, int ms) {
	BattleFireFDSet fdset;
	memset(&fdset, 0, sizeof(BattleFireFDSet));
	timeval timeout = { second,ms };
#ifdef BATTLEFIRE_PLATFORM_WIN
	fdset.fd_count = 1;
	fdset.fd_array[0] = fd;
	int nCount = select(0, &fdset, NULL, NULL, &timeout);
	return nCount == 1;
#elif BATTLEFIRE_PLATFORM_UNIX
	FD_SET(fd, &fdset);
	if (select(fd + 1, NULL, &fdset, NULL, &timeout) <= 0) {
		return false;
	}
	if (FD_ISSET(fd, &fdset)) {
		return true;
	}
	return false;
#endif
}